import React, { Component } from 'react';
import { Scroller, Touchable } from '$yo-component';
import Header from '$component/header/index.js';
import yoHistory from '$common/history';
import './index.scss';
import CommentChild from "$component/comment/comment.js";

class Comment extends Component {
    constructor() {
        super()
        this.state = {
            title:'',
            data:[{    //设置初始状态格式
                comment:'qwe',
                zan:'2'
            }],
            size:'1'  //注意数量 防止第一次渲染报错，导致bug
        };
    }

    componentWillMount() {
        var tableNum = this.props.params.navsId;
        var newsId = this.props.params.news_id;
        const that = this;
        
         $.ajax({
            url:'http://www.fujiqing-yo.online/api/comment_h.php',
            type:'post',
            dataType:'json',
            data:{
                newsId:newsId, //新闻id
                type:tableNum   //新闻类型
            },
            success:function(result){ 
               that.setState({
                    data:result,
                    size:result.length
                })
            }
        })
    }
    render() {
        var tableNum = this.props.params.navsId;
        var newsTitle = this.props.params.newsTitle;
        var newsId = this.props.params.news_id;
        
        return (
            <div className="yo-flex">
                <Scroller extraClass="flex" onScroll={() => {  
                }}> 
                   <Header title="网易"/>
                    <h1>话题：{newsTitle}</h1>
                    <Touchable
                        touchClass="touchable-highlight"
                        onTap={()=> {
                           yoHistory.go(-1)
                        }}
                    >
                        
                            <p className="check">查看原文</p>
                        
                    </Touchable>
                    <form action="http://www.fujiqing-yo.online/api/comment_w.php" method="post" className="clear">
                        <textarea name="comment" ></textarea>
                        <input className="hid" type="text" name="type" value={tableNum}/>
                        <input className="hid" type="text" name="news_id" value={newsId}/>
                        <input type="submit" className="yo-btn" name="submit" value="发布"/>
                    </form>
                    <CommentChild title="true" data={this.state.data} size={this.state.size}/>
                    <CommentChild data={this.state.data} size={this.state.size}/>
                </Scroller>
            </div>
        )
    }
}

Comment.defaultProps = {

}

export default Comment;